{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}
{% set _preview	  = block('preview') %}
{% set _form		 = block('form') %}
{% set _show		 = block('show') %}
{% set _list_table   = block('list_table') %}
{% set _list_filters = block('list_filters') %}
{% set _side_menu	= block('side_menu') %}
{% set _content	  = block('content') %}
{% set _title		= block('title') %}
{% set _breadcrumb   = block('breadcrumb') %}
{% set _actions	  = block('actions') %}
<!DOCTYPE html>
<html {% block html_attributes %}class="no-js"{% endblock %}>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		{% block stylesheets %}
			<!-- jQuery code -->
			<link rel="stylesheet" href="{{ asset('bundles/sonatajquery/themes/flick/jquery-ui-1.8.16.custom.css') }}" type="text/css" media="all" />

			<link rel="stylesheet" href="{{ asset('bundles/sonataadmin/bootstrap/css/bootstrap.min.css') }}" type="text/css" media="all"  />
			<link rel="stylesheet" href="{{ asset('bundles/sonataadmin/bootstrap/css/bootstrap-responsive.min.css') }}" type="text/css" media="all" />

			{% if admin_pool is defined and admin_pool.getOption('use_select2') %}
				<link rel="stylesheet" href="{{ asset('bundles/sonataadmin/select2/select2.css') }}" type="text/css" media="all" />
				<style>
					div.select2-container {
						margin-left: 0px !important;
					}

					div.select2-drop ul {
						margin: 0px !important;
					}
				</style>
			{% endif %}

			<!-- base application asset -->
			<link rel="stylesheet" href="{{ asset('bundles/sonataadmin/css/layout.css') }}" type="text/css" media="all" />
			<link rel="stylesheet" href="{{ asset('bundles/sonataadmin/css/colors.css') }}" type="text/css" media="all" />

		{% endblock %}

		{% block javascripts %}
			<script type="text/javascript">
				window.SONATA_CONFIG = {
					CONFIRM_EXIT: {% if admin_pool is defined and admin_pool.getOption('confirm_exit') %}true{% else %}false{% endif %},
					USE_SELECT2: {% if admin_pool is defined and admin_pool.getOption('use_select2') %}true{% else %}false{% endif %}
				};
				window.SONATA_TRANSLATIONS = {
					CONFIRM_EXIT:  '{{ 'confirm_exit'|trans({}, 'SonataAdminBundle')|escape('js') }}'
			   };
			</script>
			<script src="{{ asset('bundles/sonatajquery/jquery-1.8.3.js') }}" type="text/javascript"></script>
			<script src="{{ asset('bundles/sonatajquery/jquery-ui-1.8.23.js') }}" type="text/javascript"></script>
			<script src="{{ asset('bundles/sonatajquery/jquery-ui-i18n.js') }}" type="text/javascript"></script>

			<script src="{{ asset('bundles/sonataadmin/bootstrap/js/bootstrap.min.js') }}" type="text/javascript"></script>

			{% if admin_pool is defined and admin_pool.getOption('use_select2') %}
				<script src="{{ asset('bundles/sonataadmin/select2/select2.min.js') }}" type="text/javascript"></script>
			{% endif %}

			<script src="{{ asset('bundles/sonataadmin/jquery/jquery.form.js') }}" type="text/javascript"></script>
			{% if admin_pool is defined and admin_pool.getOption('confirm_exit') %}<script src="{{ asset('bundles/sonataadmin/jquery/jquery.confirmExit.js') }}" type="text/javascript"></script>{% endif %}
			<script src="{{ asset('bundles/sonataadmin/base.js') }}" type="text/javascript"></script>
		{% endblock %}

		<title>
			{{ 'Admin'|trans({}, 'SonataAdminBundle') }}

			{% if _title is not empty %}
				{{ _title|raw }}
			{% else %}
				{% if action is defined %}
					-
					{% for menu in admin.breadcrumbs(action) %}
						{% if not loop.first  %}
							&gt;
						{% endif %}
						{{ menu.label }}
					{% endfor %}
				{% endif %}
			{% endif%}
		</title>
	</head>
	<body class="sonata-bc {% if _side_menu is empty %}sonata-ba-no-side-menu{% endif %}">
		{# initialize block value #}

		<div class="navbar navbar-fixed-top">
			<div class="navbar-inner">
				<div class="container-fluid">
					<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</a>

					{% if admin_pool is defined %}
						<div class="navbar-text pull-right">{% include admin_pool.getTemplate('user_block') %}</div>

						{% block logo %}
							<a href="{{ url('sonata_admin_dashboard') }}" class="brand">
								<img src="{{ asset(admin_pool.titlelogo) }}"  alt="{{ admin_pool.title }}" />
								{{ admin_pool.title }}
							</a>
						{% endblock %}

						{% block sonata_nav_menu %}
							<div class="nav-collapse">
								<ul class="nav">
									{% block top_bar_before_nav %} {% endblock %}
									{% block sonata_top_bar_nav %}
										{% if app.security.token and is_granted('ROLE_SONATA_ADMIN') %}
											{% for group in admin_pool.dashboardgroups %}
												{% set display = (group.roles is empty or is_granted('ROLE_SUPER_ADMIN') ) %}
												{% for role in group.roles if not display %}
													{% set display = is_granted(role) %}
												{% endfor %}

												{# Do not display the group label if no item in group is available #}
												{% set item_count = 0 %}
												{% if display %}
													{% for admin in group.items if item_count == 0 %}
														{% if admin.hasroute('list') and admin.isGranted('LIST') %}
															{% set item_count = item_count+1 %}
														{% endif %}
													{% endfor %}
												{% endif %}

												{% if display and (item_count > 0) %}
												<li class="dropdown">
													<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ group.label|trans({}, group.label_catalogue) }} <span class="caret"></span></a>
													<ul class="dropdown-menu">
														{% for admin in group.items %}
															{% if admin.hasroute('list') and admin.isGranted('LIST') %}
																<li><a href="{{ admin.generateUrl('list')}}">{{ admin.label|trans({}, admin.translationdomain) }}</a></li>
															{% endif %}
														{% endfor %}
													</ul>
												</li>
												{% endif %}
											{% endfor %}
										{% endif %}
									{% endblock %}
									{% block top_bar_after_nav %} {% endblock %}
								</ul>
							</div>
						{% endblock %}
					{% endif %}
				</div>
			</div>
		</div>

		<div class="container-fluid">
			{% block sonata_page_content %}
				{% block notice %}
					{% for notice_level in ['success','error','info', 'warning'] %}
						{% set session_var = 'sonata_flash_' ~ notice_level %}
						{% for flash in app.session.flashbag.get(session_var) %}
							<div class="alert {{ 'alert-' ~ notice_level }}">
								{{ flash|trans([], 'SonataAdminBundle') }}
							</div>
						{% endfor %}
					{% endfor %}
				{% endblock %}

				<div class="row-fluid">
					{% if _breadcrumb is not empty or action is defined %}
						<div class="span6">
							<ul class="breadcrumb">
								{% if _breadcrumb is empty %}
									{% if action is defined %}
										{% for menu in admin.breadcrumbs(action) %}
											{% if not loop.last  %}
												<li>
													{% if menu.uri is not empty %}
														<a href="{{ menu.uri }}">{{ menu.label }}</a>
													{% else %}
														{{ menu.label }}
													{% endif %}
													<span class="divider">/</span>
												</li>
											{% else %}
												<li class="active">{{ menu.label }}</li>
											{% endif %}
										{% endfor %}
									{% endif %}
								{% else %}
									{{ _breadcrumb|raw }}
								{% endif %}
							</ul>
						</div>
					{% endif %}

					{% if _actions is not empty %}
						<div class="span4 offset2">
							{{ _actions|raw }}
						</div>
					{% endif %}
				</div>

				<div class="row-fluid">
					{% if _side_menu is not empty %}
						<div class="sidebar span2">
							<div class="well sonata-ba-side-menu" style="padding: 8px 0;">{{ _side_menu|raw }}</div>
						</div>
					{% endif %}

					<div class="content {{ _side_menu is not empty ? ' span10' : 'span12' }}">
						{% block sonata_admin_content %}

							{% if _preview is not empty %}
								<div class="sonata-ba-preview">{{ _preview|raw }}</div>
							{% endif %}

							{% if _content is not empty %}
								<div class="sonata-ba-content">{{ _content|raw }}</div>
							{% endif %}

							{% if _show is not empty %}
								<div class="sonata-ba-show">{{ _show|raw }}</div>
							{% endif %}

							{% if _form is not empty %}
								<div class="sonata-ba-form">{{ _form|raw }}</div>
							{% endif %}

							{% if _list_table is not empty or _list_filters is not empty %}
								<div class="row-fluid">
									<div class="sonata-ba-list span10">
										{{ _list_table|raw }}
									</div>
									<div class="sonata-ba-filter span2">
										{{ _list_filters|raw }}
									</div>
								</div>
							{% endif %}

						{% endblock %}
					</div>
				</div>
			{% endblock %}
		</div>
	</body>
</html>
